{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**stations**  \n",
    " For reference, ignored during import  \n",
    " StationReference Format:   \n",
    "     \n",
    " |Name | MayBeInitial | Platforms |  \n",
    " |--|--|--|\n",
    " |a = 武九客专武汉方向 | 1 | 2, 1   |\n",
    " |b = 葛店南 | 1 | 1, 6, 4, 2, 3, 5  | \n",
    " |c = 武冈城际黄冈方向 | 1 | 1, 2   |\n",
    " |d = 武九客专鄂州方向 | 1 | 1, 2  | \n",
    "\n",
    "**timetable**  \n",
    " Format: \n",
    " ReportingNumber TrainType MaxSpeedKmph TrainComposition Flags : StationVisit1 StationVisit2 ...  \n",
    "\n",
    " StationVisit format:  \n",
    " StationReferencePlatformNumberFromDurationMinutes  \n",
    "\n",
    " TrainType format:  \n",
    " COMMUTER | FREIGHT | IC | URBAN  \n",
    "\n",
    " TrainComposition format:  \n",
    " vvv...  \n",
    " Each v represents one vehicle. L = locomotive (or control post), C = cargo car, P = passenger car  \n",
    " \n",
    " Flags format:  \n",
    " ff  \n",
    " Each f is one flag. 0 = flag not set, 1 = flag set, X = position not used  \n",
    " Flag positions:  \n",
    " 1 unused (X)  \n",
    " 2 NoBrakingPenalization - if set (1), train does NOT receive penalization when braking at signals  \n",
    "\n",
    "**例子**\n",
    "|列车编号|类型|最高时速|动拖布置|flag|车站1|车站2|车站3|  \n",
    "|--|--|--|--|--|--|--|--|\n",
    "|D3223 |COMMUTER |200 |LPPL |X1: | a#1#17:44:00#0 |b#3#17:46:00#2 |c#1#17:50:00#0  |"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**车次相关信息**  \n",
    "    车次信息不变 默认commuter  \n",
    "    依照类型设置最高速度 D->200 G->300  \n",
    "    车辆细节 先默认 MTTM 后续修改长编或者重连?  \n",
    "  \n",
    "\n",
    "**停站相关信息**  \n",
    "    仅三点式 进场车站 停站 离场车站  \n",
    "    车站 筛选所有车次始发终到，设置字典更改进场离场  \n",
    "    股道指定 随机指定？  \n",
    "  \n",
    "\n",
    "**表格信息**  \n",
    "从路路通截图导出为Excel进行处理  \n",
    "![格式](表格格式.png)  \n",
    "始发站和终到站更换为进场车站和离场车站  \n",
    "  \n",
    "\n",
    "**车站信息**  \n",
    "![车站](线路关系.png)  \n",
    "单个车站及进场离场布置  \n",
    "  "
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**库函数部分及常规列车信息部分**  \n",
    "导入库函数，处理表格以及替换字符并导出  \n",
    "使用字典建立常规信息的映射关系  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy\n",
    "import pandas\n",
    "import datetime\n",
    "import random\n",
    "\n",
    "Excelpath=\"gdn.xlsx\" #表格文件路径\n",
    "TextPath=\"trains武汉东.txt\"#文本文件\n",
    "speed = {'K': '120', 'T': '140', 'Z': '160',\n",
    "         'D': '200', 'C': '200', 'G': '300'}  # 速度映射关系\n",
    "# 车站-编号,股道,股道到达及用时映射关系\n",
    "# 股道到达映射关系.可到达股道,图片左右侧线路key值不同则掉向,\n",
    "station = {'武九客专武汉方向': ['b', '135', '0',20],'余花联络线武汉东方向':['c', '135', '0',20], '葛店南': ['e', '123456', '',0],\n",
    "           '武冈城际黄冈方向': ['f', '46', '1',5], '武九客专鄂州方向': ['g', '24', '1',5]}\n",
    "ThisStation = '葛店南'\n",
    "# track = {'武九客专武汉方向': '135',\n",
    "#          '武冈城际黄冈方向': '46', '武九客专鄂州方向': '24'}\n",
    "# 车型关系--待筛选，默认短编\n",
    "marshalling = {}\n",
    "\n",
    "# 始发终到映射关系--待筛选\n",
    "dst = {}\n",
    "\n",
    "# 股道到达,图片左右侧线路,,key值不同则掉向\n",
    "# turnst = {'武九客专武汉方向': 0, '武九客专鄂州方向': 1, '武冈城际黄冈方向': 1}\n",
    "\n",
    "trainDF = pandas.DataFrame(\n",
    "    columns=['列车编号', '类型', '最高时速', '动拖布置', 'flag'])  # 列车整体信息\n",
    "arriveStDF = pandas.DataFrame(columns=['车站名称', '股道', '到达时间', '停站时间'])  # 进场信息\n",
    "stopStDF = pandas.DataFrame(columns=['车站名称', '股道', '到达时间', '停站时间'])  # 停站信息\n",
    "leaveStDF = pandas.DataFrame(columns=['车站名称', '股道', '到达时间', '停站时间'])  # 离场信息\n",
    "\n",
    "# 存储字符串形式的最终结果\n",
    "trainList=[]\n",
    "arriveStList = []\n",
    "stopStList = []\n",
    "leaveStList = []\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**读取表格及数据处理部分**  \n",
    ">1,读取表格并去除空行  \n",
    ">2,从车次提取速度等级  \n",
    ">3,筛选始发站终到站建立替换字典  \n",
    "  \n",
    "  \n",
    "**车次字符串生成部分**\n",
    ">1,车次信息部分\n",
    ">>车次号,类型,动拖布置及flag保持默认  \n",
    ">>速度等级依照KTZDG等区分映射  \n",
    "\n",
    ">2,停站部分  \n",
    ">>停站2(主要车站) 到时及停站时间来自表格部分  股道随机  \n",
    ">>进场及离场部分 依照游戏先期测试进行平移推算  股道依照上下行安排  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    车次名称        到时        开时  始发站  终到站\n",
      "0  C5602  07:23:00  07:25:00  黄冈西   武汉\n",
      "1  D5770  07:53:00  07:55:00  大冶北  云梦东\n",
      "2  D5782  08:23:00  08:25:00  黄冈东   利川\n",
      "3  D5762  08:57:00  08:59:00  黄冈东   仙桃\n",
      "4  D2181  10:42:00  10:44:00   武汉  黄梅东\n",
      "{'重庆北', '黄冈西', '深圳北', '仙桃', '厦门北', '云梦东', '武汉东', '咸宁南', '厦门', '汉口', '南昌西', '武穴北', '阳新', '梅州西', '西安北', '黄梅东', '武汉', '黄冈东', '杭州西', '郑州东', '利川', '南昌', '宜昌东', '大冶北'}\n"
     ]
    }
   ],
   "source": [
    "# 读取文件\n",
    "sheet = pandas.read_excel(io=Excelpath)\n",
    "\n",
    "sheet = sheet.dropna()\n",
    "sheet=sheet.reset_index(drop=True)\n",
    "\n",
    "print(sheet.head())\n",
    "\n",
    "trainInfo = sheet[\"车次名称\"].to_frame()  # 车辆信息\n",
    "#统计始发终到车站信息\n",
    "ts=pandas.concat([sheet[\"始发站\"].value_counts(),sheet[\"终到站\"].value_counts()])\n",
    "totalStation=ts.index\n",
    "\n",
    "print(set(list(totalStation))) #所有始发站和终到站统计"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'云梦东': '余花联络线武汉东方向',\n",
       " '仙桃': '余花联络线武汉东方向',\n",
       " '利川': '武九客专武汉方向',\n",
       " '南昌': '武九客专鄂州方向',\n",
       " '南昌西': '武九客专鄂州方向',\n",
       " '厦门': '武九客专鄂州方向',\n",
       " '厦门北': '武九客专鄂州方向',\n",
       " '咸宁南': '余花联络线武汉东方向',\n",
       " '大冶北': '武九客专鄂州方向',\n",
       " '宜昌东': '余花联络线武汉东方向',\n",
       " '杭州西': '武九客专鄂州方向',\n",
       " '梅州西': '武九客专鄂州方向',\n",
       " '武汉': '武九客专武汉方向',\n",
       " '武汉东': '武九客专武汉方向',\n",
       " '武穴北': '武冈城际黄冈方向',\n",
       " '汉口': '余花联络线武汉东方向',\n",
       " '深圳北': '武九客专鄂州方向',\n",
       " '西安北': '武九客专武汉方向',\n",
       " '郑州东': '武九客专武汉方向',\n",
       " '重庆北': '武九客专武汉方向',\n",
       " '阳新': '武九客专鄂州方向',\n",
       " '黄冈东': '武冈城际黄冈方向',\n",
       " '黄冈西': '武冈城际黄冈方向',\n",
       " '黄梅东': '武冈城际黄冈方向'}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 手动建立映射关系\n",
    "ArrLeaveSt = {'云梦东': '余花联络线武汉东方向',\n",
    "              '仙桃': '余花联络线武汉东方向',\n",
    "              '利川': '武九客专武汉方向',\n",
    "              '南昌': '武九客专鄂州方向',\n",
    "              '南昌西': '武九客专鄂州方向',\n",
    "              '厦门': '武九客专鄂州方向',\n",
    "              '厦门北': '武九客专鄂州方向',\n",
    "              '咸宁南': '余花联络线武汉东方向',\n",
    "              '大冶北': '武九客专鄂州方向',\n",
    "              '宜昌东': '余花联络线武汉东方向',\n",
    "              '杭州西': '武九客专鄂州方向',\n",
    "              '梅州西': '武九客专鄂州方向',\n",
    "              '武汉': '武九客专武汉方向',\n",
    "              '武汉东': '武九客专武汉方向',\n",
    "              '武穴北': '武冈城际黄冈方向',\n",
    "              '汉口': '余花联络线武汉东方向',\n",
    "              '深圳北': '武九客专鄂州方向',\n",
    "              '西安北': '武九客专武汉方向',\n",
    "              '郑州东': '武九客专武汉方向',\n",
    "              '重庆北': '武九客专武汉方向',\n",
    "              '阳新': '武九客专鄂州方向',\n",
    "              '黄冈东': '武冈城际黄冈方向',\n",
    "              '黄冈西': '武冈城际黄冈方向',\n",
    "              '黄梅东': '武冈城际黄冈方向'}\n",
    "ArrLeaveSt \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>列车编号</th>\n",
       "      <th>类型</th>\n",
       "      <th>最高时速</th>\n",
       "      <th>动拖布置</th>\n",
       "      <th>flag</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>C5602</td>\n",
       "      <td>COMMUTER</td>\n",
       "      <td>200</td>\n",
       "      <td>LPPL</td>\n",
       "      <td>X1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>D5770</td>\n",
       "      <td>COMMUTER</td>\n",
       "      <td>200</td>\n",
       "      <td>LPPL</td>\n",
       "      <td>X1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>D5782</td>\n",
       "      <td>COMMUTER</td>\n",
       "      <td>200</td>\n",
       "      <td>LPPL</td>\n",
       "      <td>X1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>D5762</td>\n",
       "      <td>COMMUTER</td>\n",
       "      <td>200</td>\n",
       "      <td>LPPL</td>\n",
       "      <td>X1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>D2181</td>\n",
       "      <td>COMMUTER</td>\n",
       "      <td>200</td>\n",
       "      <td>LPPL</td>\n",
       "      <td>X1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    列车编号        类型 最高时速  动拖布置 flag\n",
       "0  C5602  COMMUTER  200  LPPL   X1\n",
       "1  D5770  COMMUTER  200  LPPL   X1\n",
       "2  D5782  COMMUTER  200  LPPL   X1\n",
       "3  D5762  COMMUTER  200  LPPL   X1\n",
       "4  D2181  COMMUTER  200  LPPL   X1"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#'列车编号','类型','最高时速','动拖布置','flag' 列车整体信息\n",
    "\n",
    "for index,row in trainInfo.iterrows():\n",
    "    trainNum=row[\"车次名称\"]\n",
    "    maxspeed=speed.get(trainNum[0])#有字头的列车\n",
    "    if maxspeed==None: #最高速度未找到\n",
    "        maxspeed='120' #普客\n",
    "    \n",
    "    #trainTC=marshalling.get() #动拖布置\n",
    "    trainDF.loc[index]=[trainNum,\"COMMUTER\",maxspeed,\"LPPL\",\"X1\"]\n",
    "    trainList.append(\"{0} {1} {2} {3} {4} : \".format(trainNum,\"COMMUTER\",maxspeed,\"LPPL\",\"X1\"))\n",
    "trainDF.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# arriveStList=pandas.DataFrame(columns=['车站名称','股道','到达时间','停站时间'])#进场信息\n",
    "# stopiveStList=pandas.DataFrame(columns=['车站名称','股道','到达时间','停站时间'])#停站信息\n",
    "# leaveStList=pandas.DataFrame(columns=['车站名称','股道','到达时间','停站时间'])#离场信息\n",
    "# stationInfo = sheet[[\"到时\", \"开时\",\"始发站\", \"终到站\"]]  # 时间及停站信息\n",
    "\n",
    "for index, row in sheet.iterrows():\n",
    "    arriveSt = ArrLeaveSt.get(row[\"始发站\"])\n",
    "    leaveSt = ArrLeaveSt.get(row[\"终到站\"])\n",
    "\n",
    "    # 上下行编号区分车辆进场股道为1,2道\n",
    "\n",
    "    if int(row[\"车次名称\"].strip()[-1]) % 2 == 0:\n",
    "        arriveTrack = 2  # 偶数位上行车\n",
    "    else:\n",
    "        arriveTrack = 1  # 奇数下行\n",
    "    # 依照掉向区分离场股道\n",
    "    if (station.get(arriveSt))[2] == (station.get(leaveSt))[2]:\n",
    "        leaveTrack = arriveTrack\n",
    "    else:\n",
    "        leaveTrack = 3-arriveTrack  # 2->1,1->2\n",
    "\n",
    "    # 停站股道,依照映射随机选择\n",
    "    stopTrack = random.choice((station.get(arriveSt)[1]))\n",
    "\n",
    "    at=row[\"到时\"]\n",
    "    lt=row[\"开时\"]\n",
    "    # 统一时间格式\n",
    "    strTime1 = datetime.datetime.strptime(str(at), \"%H:%M:%S\")\n",
    "    strTime2 = datetime.datetime.strptime(str(lt), \"%H:%M:%S\")\n",
    "\n",
    "    stopTime = (strTime2-strTime1).seconds/60  # 分钟为单位的停站时间\n",
    "\n",
    "    arrTime1=strTime1-datetime.timedelta(minutes=(station.get(arriveSt))[3])\n",
    "    #print((str(arrTime1))[10,-1])\n",
    "    arrTime2=str(arrTime1.strftime('%Y-%m-%d %H:%M:%S'))[-8:]\n",
    "    arrTime=datetime.datetime.strptime(arrTime2, \"%H:%M:%S\")\n",
    "\n",
    "    leaveTime1=strTime2+datetime.timedelta(minutes=(station.get(leaveSt))[3])\n",
    "    leaveTime2=str(leaveTime1.strftime('%Y-%m-%d %H:%M:%S'))[-8:]\n",
    "    leaveTime=datetime.datetime.strptime(leaveTime2, \"%H:%M:%S\")\n",
    "\n",
    "    # 进场\n",
    "    arriveStDF.loc[index] = [arriveSt, arriveTrack, arrTime2, 0]\n",
    "    arriveStList.append(\"{0}#{1}#{2}#{3}\".format(\n",
    "        (station.get(arriveSt))[0], arriveTrack, arrTime2, 0))\n",
    "    # 停站\n",
    "    stopStDF.loc[index] = [ThisStation, stopTrack, row[\"到时\"], stopTime]\n",
    "    stopStList.append(\"{0}#{1}#{2}#{3}\".format(\n",
    "        (station.get(ThisStation))[0], stopTrack, row[\"到时\"], int(stopTime)))\n",
    "\n",
    "    # 离场\n",
    "    leaveStDF.loc[index] = [leaveSt, leaveTrack, leaveTime2, 0]\n",
    "    leaveStList.append(\"{0}#{1}#{2}#{3}\".format(\n",
    "        (station.get(leaveSt))[0], leaveTrack, leaveTime2, 0))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "       车站名称  股道      到达时间  停站时间\n",
      "0  武冈城际黄冈方向   2  07:18:00     0\n",
      "1  武九客专鄂州方向   2  07:48:00     0\n",
      "2  武冈城际黄冈方向   2  08:18:00     0\n",
      "3  武冈城际黄冈方向   2  08:52:00     0\n",
      "4  武九客专武汉方向   1  10:22:00     0 \n",
      "   车站名称 股道      到达时间  停站时间\n",
      "0  葛店南  4  07:23:00   2.0\n",
      "1  葛店南  2  07:53:00   2.0\n",
      "2  葛店南  4  08:23:00   2.0\n",
      "3  葛店南  6  08:57:00   2.0\n",
      "4  葛店南  3  10:42:00   2.0 \n",
      "          车站名称  股道      到达时间  停站时间\n",
      "0    武九客专武汉方向   1  07:45:00     0\n",
      "1  余花联络线武汉东方向   1  08:15:00     0\n",
      "2    武九客专武汉方向   1  08:45:00     0\n",
      "3  余花联络线武汉东方向   1  09:19:00     0\n",
      "4    武冈城际黄冈方向   2  10:49:00     0\n"
     ]
    }
   ],
   "source": [
    "print(arriveStDF.head(),'\\n',stopStDF.head(),'\\n',leaveStDF.head())"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**最终车次结果**  \n",
    "合并车辆信息和停站信息  \n",
    "  \n",
    "**导出部分**  \n",
    "导出为train.txt手动附加原文件头部之后替换原时刻表文件  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['C5602 COMMUTER 200 LPPL X1 : f#2#07:18:00#0 e#4#07:23:00#2 b#1#07:45:00#0 ',\n",
       " 'D5770 COMMUTER 200 LPPL X1 : g#2#07:48:00#0 e#2#07:53:00#2 c#1#08:15:00#0 ',\n",
       " 'D5782 COMMUTER 200 LPPL X1 : f#2#08:18:00#0 e#4#08:23:00#2 b#1#08:45:00#0 ',\n",
       " 'D5762 COMMUTER 200 LPPL X1 : f#2#08:52:00#0 e#6#08:57:00#2 c#1#09:19:00#0 ',\n",
       " 'D2181 COMMUTER 200 LPPL X1 : b#1#10:22:00#0 e#3#10:42:00#2 f#2#10:49:00#0 ',\n",
       " 'D3287 COMMUTER 200 LPPL X1 : b#1#10:46:00#0 e#5#11:06:00#2 g#2#11:13:00#0 ',\n",
       " 'D5742 COMMUTER 200 LPPL X1 : f#2#11:25:00#0 e#6#11:30:00#2 c#1#11:52:00#0 ',\n",
       " 'D5852 COMMUTER 200 LPPL X1 : g#2#12:01:00#0 e#2#12:06:00#2 b#1#12:28:00#0 ',\n",
       " 'G2387 COMMUTER 300 LPPL X1 : b#1#12:37:00#0 e#5#12:57:00#6 g#2#13:08:00#0 ',\n",
       " 'D5765 COMMUTER 200 LPPL X1 : c#1#12:50:00#0 e#5#13:10:00#2 g#2#13:17:00#0 ',\n",
       " 'D5853 COMMUTER 200 LPPL X1 : b#1#12:55:00#0 e#1#13:15:00#2 f#2#13:22:00#0 ',\n",
       " 'D3273 COMMUTER 200 LPPL X1 : c#1#13:03:00#0 e#1#13:23:00#2 g#2#13:30:00#0 ',\n",
       " 'C5626 COMMUTER 200 LPPL X1 : f#2#13:24:00#0 e#4#13:29:00#2 b#1#13:51:00#0 ',\n",
       " 'D5881 COMMUTER 200 LPPL X1 : c#1#13:21:00#0 e#5#13:41:00#2 g#2#13:48:00#0 ',\n",
       " 'G2388 COMMUTER 300 LPPL X1 : g#2#13:38:00#0 e#4#13:43:00#2 b#1#14:05:00#0 ',\n",
       " 'D2182 COMMUTER 200 LPPL X1 : f#2#13:49:00#0 e#4#13:54:00#3 b#1#14:17:00#0 ',\n",
       " 'G2046 COMMUTER 300 LPPL X1 : g#2#14:42:00#0 e#4#14:47:00#2 b#1#15:09:00#0 ',\n",
       " 'G2294 COMMUTER 300 LPPL X1 : g#2#15:01:00#0 e#4#15:06:00#3 b#1#15:29:00#0 ',\n",
       " 'G2712 COMMUTER 300 LPPL X1 : g#2#15:43:00#0 e#2#15:48:00#2 b#1#16:10:00#0 ',\n",
       " 'D3274 COMMUTER 200 LPPL X1 : g#2#15:51:00#0 e#2#15:56:00#2 c#1#16:18:00#0 ',\n",
       " 'D5855 COMMUTER 200 LPPL X1 : b#1#16:15:00#0 e#1#16:35:00#2 f#2#16:42:00#0 ',\n",
       " 'D3251 COMMUTER 200 LPPL X1 : b#1#17:02:00#0 e#1#17:22:00#2 g#2#17:29:00#0 ',\n",
       " 'D5856 COMMUTER 200 LPPL X1 : f#2#17:17:00#0 e#4#17:22:00#2 b#1#17:44:00#0 ',\n",
       " 'D3223 COMMUTER 200 LPPL X1 : b#1#17:24:00#0 e#1#17:44:00#2 g#2#17:51:00#0 ']"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "timeTable =open(TextPath,mode=\"a\")\n",
    "finalRes=[]\n",
    "for i in range(0,len(arriveStList)):\n",
    "    tstr=\"{0}{1} {2} {3} \".format(trainList[i],arriveStList[i],stopStList[i],leaveStList[i])\n",
    "    finalRes.append(tstr)\n",
    "    tstr1=tstr+'\\n'\n",
    "    timeTable.writelines(tstr1)\n",
    "\n",
    "timeTable.close()\n",
    "finalRes\n",
    "\n",
    "\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.2"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
